﻿using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;
using HuaCheng.CommonClass;
using HuaCheng.Model;
using System;
using System.Collections.Generic;
using System.Data;

namespace HuaCheng.Controller
{
    public class StepControl
    {
        /// <summary>
        /// 规范化记录条件上下限的值
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string SetRecordRangeFormat(string value)
        {
            char[] arr = value.ToCharArray();
            string str = "";
            int i = 0;
            for (i = 0; i < arr.Length; i++)
            {
                if (arr[i] >= 48 && arr[i] <= 57 || arr[i] == 46)
                {
                    str += arr[i];
                }
                else
                {
                    break;
                }
            }
            return Convert.ToString(str);
        }
        /// <summary>
        /// 根据TreeList和保护条件生成工步信息列表
        /// </summary>
        /// <param name="treeList"></param>
        /// <returns></returns>
        public static List<StepInfo> GetStepInfoByTreeList(TreeList treeList)
        {
            List<StepInfo> stepList = new List<StepInfo>();
            //遍历treeList节点
            for (int i = 0; i < treeList.Nodes.Count; i++)
            {
                StepInfo stepInfo = GetStepInfoByTreeListNode(treeList, i);
                stepList.Add(stepInfo);
            }
            return stepList;
        }
        /// <summary>
        /// 提取treeList节点为StepInfo对象
        /// </summary>
        /// <param name="treeList"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        public static StepInfo GetStepInfoByTreeListNode(TreeList treeList, int i)
        {
            StepInfo stepInfo = new StepInfo();
            List<ChildStep> childStepList = new List<ChildStep>();//写在外面，不管有没有子节点，都要实例化对象,以免出现空指针异常
            DataTable dataTable = new DataTable();
            stepInfo.Dt = dataTable;//不管有没有工况表，都要先实例化对象
            stepInfo.CollectTime = new List<string>();//不管有没有采集时间，都要先实例化对象
            if (Convert.ToString(treeList.Nodes[i]["StepName"]).Contains("工况"))
            {
                stepInfo.StepName = Convert.ToString(treeList.Nodes[i]["StepName"]);
                stepInfo.StepNum = Convert.ToString(treeList.Nodes[i]["StepNum"]);
                if (treeList.Nodes[i]["Current"] != null && treeList.Nodes[i]["Cap"]!=null && treeList.Nodes[i]["Energy"]!=null)
                {
                    //工步时间
                    if (treeList.Nodes[i]["StepTime"] != null)
                    {
                        stepInfo.StepTime = Convert.ToString(((TimeSpan)treeList.Nodes[i]["StepTime"]).TotalMilliseconds);
                    }
                    //工况表
                    stepInfo.Dt = Collection.ToDataTable(Convert.ToString(treeList.Nodes[i]["Current"]));
                    string mode = Convert.ToString(treeList.Nodes[i]["Cap"]);
                    //模式
                    stepInfo.Mode = mode.Substring(3,mode.Length-3);
                    string magni = Convert.ToString(treeList.Nodes[i]["Energy"]);
                    //倍率
                    stepInfo.Magnification = Convert.ToSingle(magni.Substring(3,magni.Length-3));
                    //路径
                    if (treeList.Nodes[i]["DeltaVolt"] != null)
                    {
                        string strPath = Convert.ToString(treeList.Nodes[i]["DeltaVolt"]);
                        stepInfo.Path = strPath.Substring(3,strPath.Length-3);
                    }
                    //电流/功率单位
                    if(treeList.Nodes[i]["Power"]!=null)
                    {
                        string strConUnit = Convert.ToString(treeList.Nodes[i]["Power"]);
                        stepInfo.ConUnit = strConUnit.Substring(8, strConUnit .Length - 8);
                    }
                    //时间单位
                    if (treeList.Nodes[i]["LoadResistor"] != null)
                    {
                        string strTimeUnit = Convert.ToString(treeList.Nodes[i]["LoadResistor"]);
                        stepInfo.TimeUnit = strTimeUnit.Substring(5,strTimeUnit.Length - 5);
                    }
                    //保护条件勾选状态
                    if(treeList.Nodes[i]["ProtSelect"]!=null)
                    {
                        stepInfo.ProtSelect = JsonHelper.Deserialize<ProtectSelect>(treeList.Nodes[i]["ProtSelect"].ToString());
                    }
                    //保护条件
                    if(treeList.Nodes[i]["ProtCondition"]!=null)
                    {
                        stepInfo.ProtCondition = JsonHelper.Deserialize<ProtectCondition>(treeList.Nodes[i]["ProtCondition"].ToString());
                    }
                }
            }
            else
            {
                //获取stepInfo的属性
                Type type = stepInfo.GetType();
                //遍历treeList每一列
                for (int j = 0; j < treeList.Columns.Count; j++)
                {
                    string strColumn = string.Empty;
                    object copyItem = treeList.GetRowCellValue(treeList.Nodes[i], treeList.Columns[j]);
                    if (copyItem != null)
                    {
                        if (treeList.Columns[j].FieldName == "ProtSelect")
                        { 
                            //保护条件勾选状态
                            stepInfo.ProtSelect = JsonHelper.Deserialize<ProtectSelect>(treeList.Nodes[i]["ProtSelect"].ToString());
                        }
                        else if(treeList.Columns[j].FieldName == "ProtCondition")
                        {
                            //保护条件
                            stepInfo.ProtCondition = JsonHelper.Deserialize<ProtectCondition>(treeList.Nodes[i]["ProtCondition"].ToString());
                        }
                        else
                        {
                            //如果是工步时间，则格式化
                            if (copyItem.GetType() == typeof(TimeSpan))
                            {
                                strColumn = Convert.ToString(((TimeSpan)copyItem).TotalMilliseconds);
                            }
                            else
                            {
                                strColumn = Convert.ToString(copyItem);
                            }
                            //给每个属性赋表中对应单元格的值
                            type.GetProperty(treeList.Columns[j].FieldName).SetValue(stepInfo, strColumn);
                        }
                    }
                }
            }
            //如果该节点存在子节点
            if (treeList.Nodes[i].HasChildren)
            {
                TreeListNode currNode = treeList.Nodes[i];
                //遍历子节点
                for (int c = 0; c < currNode.Nodes.Count; c++)
                {
                    if (Convert.ToString(currNode.Nodes[c]["StepName"]) == "如果")
                    {
                        //若为如果工步，则将如果工步的信息加到子节点列表
                        ChildStep jumpCond = new ChildStep();
                        jumpCond.ChildStepName = "如果";
                        jumpCond.JumpCond = Convert.ToString(currNode.Nodes[c]["Voltage"]);
                        jumpCond.JumpOperator = Convert.ToString(currNode.Nodes[c]["Current"]);
                        jumpCond.JumpValue = SetRecordRangeFormat(Convert.ToString(currNode.Nodes[c]["Cap"]));
                        jumpCond.JumpTo = Convert.ToString(currNode.Nodes[c]["Energy"]);
                        childStepList.Add(jumpCond);
                    }
                    else if (Convert.ToString(currNode.Nodes[c]["StepName"]) == "记录条件")
                    {
                        //若为记录条件工步，则将记录条件工步的信息加到子节点列表
                        ChildStep recCond = new ChildStep();
                        recCond.ChildStepName = "记录条件";
                        recCond.RecordCond = Convert.ToString(currNode.Nodes[c]["StepTime"]);
                        recCond.CondLower = SetRecordRangeFormat(Convert.ToString(currNode.Nodes[c]["Current"]));
                        recCond.CondUpper = SetRecordRangeFormat(Convert.ToString(currNode.Nodes[c]["Energy"]));
                        recCond.TimeInterval = SetRecordRangeFormat(Convert.ToString(currNode.Nodes[c]["Power"]));
                        recCond.VolInterval = SetRecordRangeFormat(Convert.ToString(currNode.Nodes[c]["CutoffCurr"]));
                        recCond.CurrInterval = SetRecordRangeFormat(Convert.ToString(currNode.Nodes[c]["Slope"]));
                        childStepList.Add(recCond);
                    }
                }             
            }
            stepInfo.ChildList = childStepList;
            return stepInfo;
        }
        /// <summary>
        /// 根据工步列表生成TreeList
        /// </summary>
        /// <param name="stepList"></param>
        /// <param name="treeList"></param>
        public static TreeList SetTreeListByStepList(List<StepInfo> stepList, TreeList treeList)
        {
            treeList.ClearNodes();
            //遍历工步信息列表
            for (int i = 0; i < stepList.Count; i++)
            {
                StepInfo stepInfo = stepList[i];
                treeList = SetTreeListNodeByStepInfo(stepInfo, treeList, i);
            }
            treeList.FocusedNode = treeList.Nodes[0];
            return treeList;
        }
        /// <summary>
        /// 根据StepInfo对象生成TreeList节点
        /// </summary>
        /// <param name="stepList"></param>
        /// <param name="treeList"></param>
        /// <param name="i"></param>
        public static TreeList SetTreeListNodeByStepInfo(StepInfo stepInfo, TreeList treeList, int i)
        {
            //新增表节点
            TreeListNode tmpNode = treeList.Nodes.Add();
            if (Convert.ToString(stepInfo.StepName).Contains("工况"))
            {
                treeList.SetRowCellValue(tmpNode, treeList.Columns["StepNum"], stepInfo.StepNum);
                treeList.SetRowCellValue(tmpNode, treeList.Columns["StepName"], stepInfo.StepName);
                if (stepInfo.Dt != null && stepInfo.Mode != null)
                {
                    if (stepInfo.StepTime != null)
                    {
                        treeList.SetRowCellValue(tmpNode, treeList.Columns["StepTime"], new TimeSpan(0, 0, 0, 0, Convert.ToInt32(stepInfo.StepTime)));
                    }
                    treeList.SetRowCellValue(tmpNode, treeList.Columns["Voltage"], "工况数据：");
                    treeList.SetRowCellValue(tmpNode, treeList.Columns["Current"], Collection.ToJson(stepInfo.Dt));
                    treeList.SetRowCellValue(tmpNode, treeList.Columns["Cap"], "模式:"+stepInfo.Mode);
                    treeList.SetRowCellValue(tmpNode, treeList.Columns["Energy"], "倍率:"+Convert.ToString(stepInfo.Magnification));
                    treeList.SetRowCellValue(tmpNode, treeList.Columns["DeltaVolt"], "路径:" + Convert.ToString(stepInfo.Path));
                    treeList.SetRowCellValue(tmpNode, treeList.Columns["Power"], "电流/功率单位:" + Convert.ToString(stepInfo.ConUnit));
                    treeList.SetRowCellValue(tmpNode, treeList.Columns["LoadResistor"], "时间单位:" + Convert.ToString(stepInfo.TimeUnit));
                    treeList.SetRowCellValue(tmpNode, treeList.Columns["ProtSelect"], JsonHelper.Serialize(stepInfo.ProtSelect));
                    treeList.SetRowCellValue(tmpNode, treeList.Columns["ProtCondition"], JsonHelper.Serialize(stepInfo.ProtCondition));
                }
            }
            else
            {
                //获取stepInfo属性
                Type type = stepInfo.GetType();
                for (int j = 0; j < treeList.Columns.Count; j++)
                {
                    if (type.GetProperty(treeList.Columns[j].FieldName).GetValue(stepInfo) != null)
                    {
                        if (treeList.Columns[j].FieldName == "ProtSelect")
                        {
                            treeList.SetRowCellValue(tmpNode, treeList.Columns["ProtSelect"], JsonHelper.Serialize(stepInfo.ProtSelect));
                        }
                        else if(treeList.Columns[j].FieldName == "ProtCondition")
                        {
                            treeList.SetRowCellValue(tmpNode, treeList.Columns["ProtCondition"], JsonHelper.Serialize(stepInfo.ProtCondition));
                        }
                        else
                        {
                            if (treeList.Columns[j].FieldName == "StepTime" || treeList.Columns[j].FieldName == "Time1" || treeList.Columns[j].FieldName == "Time2")
                            {
                                if (stepInfo.StepName != "循环")
                                {
                                    treeList.SetRowCellValue(tmpNode, treeList.Columns[j], new TimeSpan(0, 0, 0, 0, Convert.ToInt32(type.GetProperty(treeList.Columns[j].FieldName).GetValue(stepInfo))));
                                }
                                else
                                {
                                    treeList.SetRowCellValue(tmpNode, treeList.Columns[j], type.GetProperty(treeList.Columns[j].FieldName).GetValue(stepInfo));
                                }
                            }
                            else
                            {
                                treeList.SetRowCellValue(tmpNode, treeList.Columns[j], type.GetProperty(treeList.Columns[j].FieldName).GetValue(stepInfo));
                            }
                        }
                    }
                }
            }
            treeList.SetNodeIndex(tmpNode, i);
            treeList.FocusedNode = tmpNode;
            if (stepInfo.ChildList != null)
            {
                Dictionary<string, string> dicCustom = IniControl.ReadCustom("unit custom");
                for (int c = 0; c < stepInfo.ChildList.Count; c++)
                {
                    ChildStep childStep = stepInfo.ChildList[c];
                    TreeListNode chlNode = tmpNode.Nodes.Add();
                    if (childStep.ChildStepName == "如果")
                    {
                        chlNode["StepName"] = childStep.ChildStepName;
                        chlNode["Voltage"] = childStep.JumpCond;
                        chlNode["Current"] = childStep.JumpOperator;
                        switch(childStep.JumpCond)
                        {
                            case "电池电压":
                                {
                                    chlNode["Cap"] = childStep.JumpValue + dicCustom["Voltage"];
                                } break;
                            case "电池电流":
                                {
                                    chlNode["Cap"] = childStep.JumpValue + dicCustom["Current"];
                                } break;
                            case "容量":
                                {
                                    chlNode["Cap"] = childStep.JumpValue + dicCustom["Cap"];
                                } break;
                            case "能量":
                                {
                                    chlNode["Cap"] = childStep.JumpValue + dicCustom["Energy"];
                                } break;
                            case "工步时间":
                                {
                                    chlNode["Cap"] = childStep.JumpValue + dicCustom["Time"];
                                } break;
                            case "主通道温度":
                                {
                                    chlNode["Cap"] = childStep.JumpValue + dicCustom["Temp"];
                                } break;
                            case "持续时间":
                                {
                                    chlNode["Cap"] = childStep.JumpValue + dicCustom["Time"];
                                } break;
                            case "环境温度":
                                {
                                    chlNode["Cap"] = childStep.JumpValue + dicCustom["Temp"];
                                } break;
                        }
                        chlNode["Energy"] = childStep.JumpTo;
                    }
                    else if (childStep.ChildStepName == "记录条件")
                    {
                        chlNode["StepName"] = childStep.ChildStepName;
                        chlNode["StepTime"] = childStep.RecordCond;
                        chlNode["Voltage"] = ">";
                        chlNode["Cap"] = "≤";
                        switch(childStep.RecordCond)
                        {
                            case "时间段":
                                chlNode["Current"] = childStep.CondLower + dicCustom["Time"];                        
                                chlNode["Energy"] = childStep.CondUpper + dicCustom["Time"];
                                break;
                            case "电压段":
                                chlNode["Current"] = childStep.CondLower + dicCustom["Voltage"];                        
                                chlNode["Energy"] = childStep.CondUpper + dicCustom["Voltage"];
                                break;
                            case "电流段":
                                chlNode["Current"] = childStep.CondLower + dicCustom["Current"];                        
                                chlNode["Energy"] = childStep.CondUpper + dicCustom["Current"];
                                break;
                        }                        
                        chlNode["DeltaVolt"] = "时间间隔";
                        chlNode["Power"] = childStep.TimeInterval+"ms";
                        chlNode["LoadResistor"] = "电压间隔";
                        chlNode["CutoffCurr"] = childStep.VolInterval+"V";
                        chlNode["BeginValue"] = "电流间隔";
                        chlNode["Slope"] = childStep.CurrInterval+"A";
                    }
                    treeList.FocusedNode = chlNode;
                }
            }
            return treeList;
        }
        /// <summary>
        /// 根据stepInfoList对象生成双电流treeList
        /// </summary>
        /// <param name="stepInfo"></param>
        /// <param name="treeList"></param>
        /// <param name="i"></param>
        /// <returns></returns>
        public static TreeList SetDoubleByStepInfo(List<StepInfo> stepInfoList, TreeList treeList)
        {
            List<TreeListNode> tLList = new List<TreeListNode>();
            //双电流有6个节点
            for (int i = 0; i < 6; i++)
            {
                TreeListNode tmpNode = treeList.Nodes.Add();
                tLList.Add(tmpNode);
                treeList.SetRowCellValue(tLList[i], treeList.Columns["Index"], i + 1);
                treeList.SetRowCellValue(tLList[i], treeList.Columns["Variate"], "");
            }
            treeList.SetRowCellValue(tLList[0], treeList.Columns["Property"], "放电电流1");
            treeList.SetRowCellValue(tLList[0], treeList.Columns["Value"], stepInfoList[0].Current);
            treeList.SetRowCellValue(tLList[0], treeList.Columns["Unit"], "A");
            treeList.SetRowCellValue(tLList[1], treeList.Columns["Property"], "运行时间1");
            treeList.SetRowCellValue(tLList[1], treeList.Columns["Value"], new TimeSpan(0, 0, 0, 0, Convert.ToInt32(stepInfoList[0].StepTime)));
            treeList.SetRowCellValue(tLList[1], treeList.Columns["Unit"], "s");
            treeList.SetRowCellValue(tLList[2], treeList.Columns["Property"], "采集时间1");
            treeList.SetRowCellValue(tLList[2], treeList.Columns["Value"], new TimeSpan(0, 0, 0, 0, Convert.ToInt32(stepInfoList[0].CollectTime[0])));
            treeList.SetRowCellValue(tLList[2], treeList.Columns["Unit"], "s");
            treeList.SetRowCellValue(tLList[3], treeList.Columns["Property"], "放电电流2");
            treeList.SetRowCellValue(tLList[3], treeList.Columns["Value"], stepInfoList[1].Current);
            treeList.SetRowCellValue(tLList[3], treeList.Columns["Unit"], "A");
            treeList.SetRowCellValue(tLList[4], treeList.Columns["Property"], "运行时间2");
            treeList.SetRowCellValue(tLList[4], treeList.Columns["Value"], new TimeSpan(0, 0, 0, 0, Convert.ToInt32(stepInfoList[1].StepTime)));
            treeList.SetRowCellValue(tLList[4], treeList.Columns["Unit"], "s");
            treeList.SetRowCellValue(tLList[5], treeList.Columns["Property"], "采集时间2");
            treeList.SetRowCellValue(tLList[5], treeList.Columns["Value"], new TimeSpan(0, 0, 0, 0, Convert.ToInt32(stepInfoList[1].CollectTime[0])));
            treeList.SetRowCellValue(tLList[5], treeList.Columns["Unit"], "s");
            return treeList;
        }
        public static TreeList SetSingleByStepInfo(List<StepInfo> stepInfoList, TreeList treeList)
        {
            List<TreeListNode> tLList = new List<TreeListNode>();
            //单电流有4个节点
            for (int i = 0; i < 4; i++)
            {
                TreeListNode tmpNode = treeList.Nodes.Add();
                tLList.Add(tmpNode);
                treeList.SetRowCellValue(tLList[i], treeList.Columns["Index"], i + 1);
                treeList.SetRowCellValue(tLList[i], treeList.Columns["Variate"], "");
            }
            treeList.SetRowCellValue(tLList[0], treeList.Columns["Property"], "放电电流1");
            treeList.SetRowCellValue(tLList[0], treeList.Columns["Value"], stepInfoList[0].Current);
            treeList.SetRowCellValue(tLList[0], treeList.Columns["Unit"], "A");
            treeList.SetRowCellValue(tLList[1], treeList.Columns["Property"], "运行时间1");
            treeList.SetRowCellValue(tLList[1], treeList.Columns["Value"], new TimeSpan(0, 0, 0, 0, Convert.ToInt32(stepInfoList[0].StepTime)));
            treeList.SetRowCellValue(tLList[1], treeList.Columns["Unit"], "s");
            treeList.SetRowCellValue(tLList[2], treeList.Columns["Property"], "采集时间1");
            treeList.SetRowCellValue(tLList[2], treeList.Columns["Value"], new TimeSpan(0, 0, 0, 0, Convert.ToInt32(stepInfoList[0].CollectTime[0])));
            treeList.SetRowCellValue(tLList[2], treeList.Columns["Unit"], "s");
            treeList.SetRowCellValue(tLList[3], treeList.Columns["Property"], "采集时间2");
            treeList.SetRowCellValue(tLList[3], treeList.Columns["Value"], new TimeSpan(0, 0, 0, 0, Convert.ToInt32(stepInfoList[0].CollectTime[1])));
            treeList.SetRowCellValue(tLList[3], treeList.Columns["Unit"], "s");
            return treeList;
        }
        /// <summary>
        /// 比较重置前后工步的变化
        /// </summary>
        /// <param name="customList"></param>
        /// <param name="loadStepList"></param>
        public static bool CompareTwoStepList(List<StepInfo> customList, List<StepInfo> loadStepList,int stepNum,bool isUpdateError)
        {
            for (int i = 0; i < stepNum-1; i++)
            {
                bool isEqual = true;
                byte[] currentBytes = SerializableControl.SerializeToBinary(customList[i]);
                byte[] lastBytes = SerializableControl.SerializeToBinary(loadStepList[i]);
                if (currentBytes == null || lastBytes == null)
                {
                    isEqual = false;
                }
                else if (currentBytes.Length != lastBytes.Length)
                {
                    isEqual = false;
                }
                else
                {
                    for (int j = 0; j < currentBytes.Length; j++)
                    {
                        if (currentBytes[j] != lastBytes[j])
                        {
                            isEqual = false;
                            break;
                        }
                    }
                }
                if (!isEqual)
                {
                    isUpdateError = true;
                    break;
                }
            }
            return isUpdateError;
        }
        /// <summary>
        /// 根据TreeList生成单电流工步
        /// </summary>
        /// <param name="treeList"></param>
        /// <returns></returns>
        public static List<StepInfo> GetSingleCurrBytreeList(TreeList treeList)
        {
            List<StepInfo> stepInfoList = new List<StepInfo>();
            StepInfo stepInfo = new StepInfo();
            stepInfo.CollectTime = new List<string>(2);
            //放电电流
            if (treeList.Nodes[0]["Value"] != null)
            {
                stepInfo.StepName = "恒流阶跃放电";
                stepInfo.Current = Convert.ToString(treeList.Nodes[0]["Value"]);
            }
            //工步执行时间
            if (treeList.Nodes[1]["Value"] != null)
            {
                stepInfo.StepTime = Convert.ToString(((TimeSpan)treeList.Nodes[1]["Value"]).TotalMilliseconds);
            }
            //采集时间1
            if (treeList.Nodes[2]["Value"] != null)
            {
                stepInfo.CollectTime.Add(Convert.ToString(((TimeSpan)treeList.Nodes[2]["Value"]).TotalMilliseconds));
            }
            //采集时间2
            if (treeList.Nodes[3]["Value"] != null)
            {
                stepInfo.CollectTime.Add(Convert.ToString(((TimeSpan)treeList.Nodes[3]["Value"]).TotalMilliseconds));
            }
            //保护条件勾选状态
            if (treeList.Nodes[0]["ProtSelect"] != null)
            {
                stepInfo.ProtSelect = JsonHelper.Deserialize<ProtectSelect>(treeList.Nodes[0]["ProtSelect"].ToString());
            }
            //保护条件
            if (treeList.Nodes[0]["ProtCondition"] != null)
            {
                stepInfo.ProtCondition = JsonHelper.Deserialize<ProtectCondition>(treeList.Nodes[0]["ProtCondition"].ToString());
            }
            stepInfoList.Add(stepInfo);
            StepInfo endStep = new StepInfo();
            endStep = getEndStep();
            stepInfoList.Add(endStep);
            return stepInfoList;
        }
        /// <summary>
        /// 根据TreeList生成双电流工步
        /// </summary>
        /// <param name="treeList"></param>
        /// <returns></returns>
        public static List<StepInfo> GetDoubleCurrBytreeList(TreeList treeList)
        {
            List<StepInfo> stepInfoList = new List<StepInfo>();
            for (int i = 0; i < 2; i++)
            {
                StepInfo stepInfo = new StepInfo();
                stepInfo.CollectTime = new List<string>();
                //放电电流
                if (treeList.Nodes[3 * i]["Value"] != null)
                {
                    stepInfo.StepName = "恒流阶跃放电";
                    stepInfo.Current = Convert.ToString(treeList.Nodes[3 * i]["Value"]);
                }
                //工步时间
                if (treeList.Nodes[3 * i + 1]["Value"] != null)
                {
                    stepInfo.StepTime = Convert.ToString(((TimeSpan)treeList.Nodes[3 * i + 1]["Value"]).TotalMilliseconds);
                }
                //采集时间
                if (treeList.Nodes[3 * i + 2]["Value"] != null)
                {
                    stepInfo.CollectTime.Add(Convert.ToString(((TimeSpan)treeList.Nodes[3 * i + 2]["Value"]).TotalMilliseconds));
                }
                //保护条件勾选状态
                if (treeList.Nodes[3*i]["ProtSelect"] != null)
                {
                    stepInfo.ProtSelect = JsonHelper.Deserialize<ProtectSelect>(treeList.Nodes[3*i]["ProtSelect"].ToString());
                }
                //保护条件
                if (treeList.Nodes[3*i]["ProtCondition"] != null)
                {
                    stepInfo.ProtCondition = JsonHelper.Deserialize<ProtectCondition>(treeList.Nodes[3*i]["ProtCondition"].ToString());
                }
                stepInfoList.Add(stepInfo);
            }
            stepInfoList.Add(getEndStep());
            return stepInfoList;
        }
        /// <summary>
        /// 获得“结束”工步
        /// </summary>
        /// <returns></returns>
        public static StepInfo getEndStep()
        {
            StepInfo endStep = new StepInfo();
            endStep.StepName = "结束";
            endStep.ProtCondition = new ProtectCondition();
            endStep.ProtSelect = new ProtectSelect();
            return endStep;
        }
    }
}
